<?php

namespace App\Http\Controllers\Index;

use App\Model\Article;
use App\Model\Tag;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class HomeController extends Controller
{


    /**
     *  //首页文章列表
     * @param page default = 1;
     * @param count default = 20;
     *
     */

    public function get_article(Request $request){
        $count =  $request->input('count','20');
        $ret = Article::where('enabled','1')->orderBy('is_top','desc')->orderBy('created_at','ASC')->paginate($count);
        if($ret){
            return response()->json([
               'code' => '1',
                'msg'=>'获取成功',
                'data'=>$ret,
            ]);
        }else{
            return response()->json([
                'code' => '0',
                'msg'=>'获取失败',
            ]);
        }
    }

    public function get_tag(Request $request){
        $ret = Tag::where('enabled',1)->get();
        return response()->json([
           'code'=>1,
           'msg'=>'获取成功',
           'data'=>$ret,
        ]);
    }

    public function login(Request $request){

        return '我是登录的接口';

    }

    public function article(Request $request){
        $id =  $request -> input('id');
        $ret = Article::where('id','=',$id)->first();
        return response()->json([
            'code'=>1,
            'msg'=>'获取成功',
            'data'=>$ret,
        ]);
    }
    public function get_test(Request $request){

    }
}
